Skip to content

Conversation

@sujeong-dev
Copy link
Contributor

@sujeong-dev sujeong-dev commented Nov 13, 2025

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@hjeomdev hjeomdev self-requested a review November 16, 2025 12:45
Copy link
Contributor

@seungriyou seungriyou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

첫 번째 주 고생 많으셨습니다!! 🚀

추가로 status를 solving에서 in review로 변경해주시면 더 빠르게 리뷰를 받으실 수 있으니 참고해주시면 감사드리겠습니다~!

*
* 시간복잡도 계산
* Set의 size속성은 입력 크기와 관계없이 일정한 시간이 걸림
* => O(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indices.size의 경우 O(1) time이 소요되지만 new Set(nums)에서 내부적으로 nums를 순회하며 원소를 삽입하기 때문에 O(n) time이 소요되므로, 전체 시간복잡도가 O(n)이 될 것 같습니다!


if (indices.size !== nums.length) return true;

return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다음과 같이 return 문을 분기 없이 간결하게 나타낼 수도 있을 것 같아요!

return indices.size !== nums.length;

* for loop가 O(n)
* reduce가 O(n)
* sort가 O(n log n)
* => O(n log n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 코드에서는 for 문 내에 findreduce가 위치하므로 전체 시간 복잡도가 O(n^2)이 될 것으로 보입니다.

* => O(n log n)
*/
var topKFrequent = function (nums, k) {
let result = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

배열이 아닌 hash map을 이용해서 값 별 frequency를 기록한다면 find로 이미 존재하는 키를 O(n)에 찾을 필요도 없고, reduce로 개수를 매번 O(n)에 계산할 필요가 없으므로 시간 복잡도 최적화가 가능할 것 같습니다!

*/
var twoSum = function (nums, target) {
for (let i = 0; i < nums.length; i++) {
for (let j = 0; j < nums.length; j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j = i + 1로 시작한다면 중복 연산도 제거할 수 있고, for 문 내부에서 i === j 비교할 필요도 없을 것 같습니다!

for (let i = 0; i < nums.length; i++) {
const findNum = target - nums[i];

if (findNum in result && result[findNum] !== i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nums.forEach()result hash map을 미리 만들어놓는 방식이 아닌, for 문을 돌며 한 번에 hash map을 점진적으로 만들어나간다면 result[findNum] !== i를 확인할 필요가 없을 것 같습니다.

@sujeong-dev sujeong-dev moved this from Solving to In Review in 리트코드 스터디 6기 Nov 16, 2025
@sujeong-dev sujeong-dev merged commit fa42511 into DaleStudy:main Nov 16, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 6기 Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

3 participants